package com.hiwetop.proxy;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fj.hiwetoptools.JsonUtil;
import com.fj.hiwetoptools.http.HttpUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by linyu on 2016/12/26.
 */
public class ProxyUtil {
    
    public static void main(String args[]) throws Exception {
        List<String> ipProxy = getProxy(getLocalProxy());
        for (String s : ipProxy) {
            System.out.println(s);
        }
    }

    /*
    # types   int 0: 高匿代理, 1 透明
    # protocol    int 0: http, 1 https
    # count   int 数量
    # country str 国家
    # area    str 地区
      必须开启114代理连接池
    */
    public static String getLocalProxy(){
        String url = "http://192.168.0.114:8000/?types=0&count=40";
        String result = HttpUtil.get(url);
        return result;
    }

    public static List<String> getProxy(String proxys) throws Exception {
        ArrayList<Object> objects = JsonUtil.toArrayList(proxys);
        List<String> list = new ArrayList<>();
        for (Object obj: objects ) {
            String s = JSONObject.toJSONString(obj);
            JSONArray objects1 = JSONArray.parseArray(s);
            list.add(new String(objects1.get(0).toString()+":"+objects1.get(1).toString()));
        }
        return list;
    }

}
